package com.huike.web.controller.report;


import com.huike.clues.domain.dto.ReportDto;
import com.huike.clues.domain.vo.ReportVo;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.page.TableDataInfo;
import com.huike.report.domain.vo.*;
import com.huike.report.service.IReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.contract.domain.TbContract;
import com.huike.report.domain.vo.LineChartVO;
import com.huike.report.service.IReportService;
import com.huike.report.service.impl.ReportServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import com.huike.report.service.IReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import com.huike.report.domain.DTO.PageDTO;
import com.huike.report.domain.page.PageReport;
import com.huike.report.service.IReportService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.print.attribute.standard.PageRanges;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

import java.time.LocalDate;

import java.text.ParseException;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;


import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/report")
public class ReportController extends BaseController {
    @Autowired
    private IReportService iReportService;

    @GetMapping("salesStatistics/{beginCreateTime}/{endCreateTime}")
    public LineChartVO salesStatistics (@PathVariable  String beginCreateTime,@PathVariable String endCreateTime){
        return iReportService.salesStatistics(beginCreateTime,endCreateTime);
    }
    @GetMapping("deptStatisticsList/{beginCreateTime}/{endCreateTime}")
    public TableDataInfo deptStatisticsList(@PathVariable String beginCreateTime,@PathVariable String endCreateTime){
        startPage();
         List<Map<String,Object>>list=iReportService.deptStatisticsList(beginCreateTime, endCreateTime);
        return getDataTablePage(list);
    }
    @GetMapping("ownerShipStatisticsList/{beginCreateTime}/{endCreateTime}")
    public TableDataInfo ownerShipStatisticsList(@PathVariable String beginCreateTime,@PathVariable String endCreateTime){
        startPage();
        List<Map<String,Object>>list=iReportService.ownerShipStatisticsList(beginCreateTime,endCreateTime);
        return getDataTablePage(list);
    }
    @GetMapping("channelStatisticsList/{beginCreateTime}/{endCreateTime}")
     public  TableDataInfo channelStatisticsList(@PathVariable String beginCreateTime,@PathVariable String endCreateTime){
        startPage();
        List<Map<String,Object>>list=iReportService.channelStatisticsList(beginCreateTime,endCreateTime);
        return getDataTablePage(list);
    }

    //客户统计


    @GetMapping("/contractStatistics/{beginCreateTime}/{endCreateTime}")
    public LineChartVO contractStatistics(@PathVariable String beginCreateTime, @PathVariable String endCreateTime) throws ParseException {
        return iReportService.contractStatistics(beginCreateTime, endCreateTime);
    }
    @GetMapping("/getVulnerabilityMap/{beginCreateTime}/{endCreateTime}")
    public AjaxResult getVulnerabilityMap(
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        VulnerabilityMapVo data = iReportService.getVulnerabilityMap(beginCreateTime, endCreateTime);
        return AjaxResult.success(data);
    }
        /**
         * 新增线索数量
         *
         * @param beginTime
         * @param endTime
         * @return
         */
    ///report/cluesStatistics
    //http://localhost:8080/report/cluesStatistics/2023-10-01/2023-10-08
    @GetMapping("/cluesStatistics/{beginTime}/{endTime}")
    public ReportVo cluesStatistics(@PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginTime,
                                    @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endTime) {
        // 1.接收参数
//        logger.info("接收到参数:{}", reportDto);
        ReportDto reportDto = new ReportDto();
        reportDto.setBeginCreateTime(beginTime);
        reportDto.setEndCreateTime(endTime);
        // 2.调用service层
        ReportVo reportVo = iReportService.getCluesStatistics(reportDto);
        // 3.响应数据
        return reportVo;
    }
    //客户统计列表查询
    @GetMapping("/contractStatisticsList")
    public TableDataInfo contractStatisticsList(TbContract tbContract) {
        startPage();//配合前端自动完成页面
        List<TbContract> list = iReportService.contractReportList(tbContract);
        return getDataTable(list);
    }


    /**
     * 线索统计报表
     *
     * @return
     */
    @GetMapping("/cluesStatisticsList")
    public TableDataInfo cluesStatisticsList(ReportDto reportDto) {
        // 1.接
        logger.info("接收到参数:{}", reportDto);
        // 2.调
        TableDataInfo tableDataInfo = iReportService.page(reportDto);
        // 3.响
        return tableDataInfo;
    }
    //学科客户分布
    @GetMapping("/subjectStatistics/{beginCreateTime}/{endCreateTime}")
    public List<Map<String,Object>> subjectStatistics(@PathVariable String beginCreateTime, @PathVariable String endCreateTime){
        return iReportService.subjectStatistics(beginCreateTime,endCreateTime);
    }



    /**
     * 活动统计饼状图
     *
     * @return
     */
    @GetMapping("/activityStatistics/{beginCreateTime}/{endCreateTime}")
    public List<ActivityStatisTicVO> activityStatisTics( @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                                                         @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        List<ActivityStatisTicVO> abc = iReportService.activityStatisTice(beginCreateTime,endCreateTime);
        return abc;
    }

    /**
     * 渠道统计报表
     * @param
     * @return
     */
    @GetMapping("/activityStatisticsList")
    public PageReport page(@DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
                           @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime,
                           String code,String name,Integer total,Integer pageNum,Integer pageSize){
        PageDTO pageDTO = new PageDTO();
        pageDTO.setBeginCreateTime(beginCreateTime);
        pageDTO.setEndCreateTime(endCreateTime);
        pageDTO.setCode(code);
        pageDTO.setName(name);
        pageDTO.setTotal(total);
        pageDTO.setPageNum(pageNum);
        pageDTO.setPageSize(pageSize);
        PageReport pageReport=iReportService.actPage(pageDTO);
       return pageReport;
    }

    /**
     * 渠道统计饼图
     */
    @GetMapping("/chanelStatistics/{beginCreateTime}/{endCreateTime}")
    public List<ChanelStatisticsVo> chanelStatistics(
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate beginCreateTime,
            @PathVariable @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endCreateTime) {
        List<ChanelStatisticsVo> chanelStatistics = iReportService.chanelStatistics(beginCreateTime, endCreateTime);
        return chanelStatistics;

    }
}